﻿@model IEnumerable<ApplicationUser>
@{
    ViewBag.Title = "登录授权";
}
<h1>@ViewBag.Title</h1>
<hr />
<form class="layui-form">
    <div class="layui-inline">
        <div class="layui-inline">
            <input type="text" placeholder="搜索姓名 或 账号" class="layui-input" name="kw" id="kw" value="@Request["kw"]" />
        </div>
    </div>
    <div class="layui-inline">
        <button id="btnSearch" class="layui-btn" type="submit">查询</button><button id="btnReset" onclick="$('#kw').val('');$('.layui-form').submit()" class="layui-btn" type="reset">重置</button>
    </div>
</form>
<table class="layui-table">
    <thead>
        <tr>
            <th>账号</th>
            <th>姓名</th>
            <th>状态</th>
            <th>创建时间</th>
            <th>上次同步</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>@item.UserName</td>
                <td>@item.RealName</td>
                <td>
                    @if (item.Enabled)
                    {
                        <span style="color:white;background-color:lightseagreen;padding:3px 5px;">可以登录</span>
                    }
                    else
                    {
                        <span style="color:  chocolate;background-color: antiquewhite;padding:3px 5px;">不可登录</span>
                    }
                </td>
                <td>@item.CreateTime</td>
                <td>@item.LastSyncAt</td>
                <td>
                    @if (item.Enabled)
                    {
                        <a style="color:cornflowerblue" title="禁止账号从MEB后台登录" href="/account/enable?id=@item.Id&type=0&returnUrl=@Request.Url.PathAndQuery">禁止登录</a>
                    }
                    else
                    {
                        <a style="color:cornflowerblue" title="允许账号从Meb后台登录" href="/account/enable?id=@item.Id&type=1&returnUrl=@Request.Url.PathAndQuery">允许登录</a>
                    }
                </td>
            </tr>
        }
    </tbody>
</table>
@using Webdiyer.WebControls.Mvc;
@Html.Pager(new PagedList<ApplicationUser>(Model, Request.GetPageIndex(), Request.GetPageSize(), ViewBag.Total), new PagerOptions
{
    PageIndexParameterName = "page",
    CurrentPagerItemWrapperFormatString = "<span class=\"layui-laypage-curr\"><em class=\"layui-laypage-em\"></em><em>{0}</em></span>",
}, new { @class = "layui-box layui-laypage layui-laypage-default" })
<p>如果列表中没有找到Meb账号，请尝试 <a title="同步Meb账号信息到本系统" href="javascript:;" style="color:cornflowerblue" id="btnSync">同步Meb账号</a></p>
@section scripts{
    <script>
        var sync = 0;
        $('#btnSync').click(function () {
            if (sync == 0) {
                sync = 1;
                layer.msg('正在同步，请稍后...', { icon: 16, time: 0 });
                $.post('/account/syncmebusers', function (d) {
                    layer.msg(d.msg);
                    if (d.code == 200) {
                        setTimeout(function () { location.reload(); }, 1000);
                    }
                    else
                        sync = 0;
                })
            }
        });
    </script>
}
